import QtQuick 2.13
import QtQuick.Controls 2.5
import QtMultimedia 5.13


Page {

    signal sigHome()

    property bool isAniEnabled: false
    property var funBacks: [backFromMenu]


    Timer {
        id: timerShowWhite
        repeat: false
        interval: 55*1000
        onTriggered: {
            resetAniOther()
        }
    }



    Rectangle {
        id: sideMenu
        width: 200
        height: 1080
        color: "black"
        opacity: 0.7
        anchors.right: parent.right
        anchors.rightMargin: -1
        anchors.top: parent.top
        border.color: Qt.rgba(255,255,255,0.2)
        border.width: 1
        z: 10

        Rectangle {
            id: back
            width: 200
            height: 193
            anchors.top: parent.top
            color: "transparent"
            visible: opacity === 0 ? false : true

            Image {
                id: imgBack
                width: 48
                height: 48
                opacity: 0
                anchors.top: parent.top
                anchors.topMargin: 70
                anchors.horizontalCenter: parent.horizontalCenter
                source: "qrc:/imgs/back.png"
                Behavior on scale { PropertyAnimation{duration:200}}
                Behavior on opacity { enabled: isAniEnabled; PropertyAnimation{duration:800}}
            }
            MouseArea {
                anchors.fill: parent
                hoverEnabled: true
                onEntered: imgBack.scale = 1.2
                onExited: imgBack.scale = 1.0
                onClicked: {
                    funBacks.pop()()
                }
            }
        }

        Rectangle {
            id: btnHome
            width: 200
            height: 193
            anchors.top: parent.top
            color: "transparent"
            opacity: 0
            visible: opacity === 0 ? false : true

            Image {
                id: imgHome
                width: 48
                height: 48
                anchors.top: parent.top
                anchors.topMargin: 70
                anchors.horizontalCenter: parent.horizontalCenter
                source: "qrc:/imgs/home.png"
                Behavior on scale { PropertyAnimation{duration:200}}
                Behavior on opacity { enabled: isAniEnabled; PropertyAnimation{duration:500}}
            }
            MouseArea {
                anchors.fill: parent
                hoverEnabled: true
                onEntered: imgHome.scale = 1.2
                onExited: imgHome.scale = 1.0
                onClicked: {
                    resetAni()
                    emit: sigHome()
                }
            }
        }

        Rectangle {
            id: line
            color: "white"
            width: 159
            height: 1
            opacity: 0.3
            anchors.top: parent.top
            anchors.topMargin: 203
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.bottomMargin: 38
        }



        ListView {
            id: listMenu
            opacity: 0.0
            visible: opacity === 0 ? false : true
            width: 200
            height: 762
            anchors.top: line.bottom
            anchors.topMargin: 700//
            anchors.horizontalCenter: parent.horizontalCenter
            spacing: 30
            clip: true

            delegate: Rectangle {
                id: deleMenu
                width: 120
                height: 120
                color: "transparent"
                anchors.horizontalCenter: parent.horizontalCenter
                property string name: model.name

                Image {
                    source: src
                    width: 120
                    height: 120
                    anchors.centerIn: parent
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            if (deleMenu.name === "bake") {
                                saHideMainMenu.start()
                                saShowBake.start()
                                funBacks.push(backFromBake)
                            }
                        }
                    }
                }
            }

            model: ListModel {
                ListElement {
                    src: "qrc:/imgs/menumode/micromode.png"
                    name: "micromode"
                }
                ListElement {
                    src: "qrc:/imgs/menumode/steammode.png"
                    name: "steammode"
                }
                ListElement {
                    src: "qrc:/imgs/menumode/bake.png"
                    name: "bake"
                }
                ListElement {
                    src: "qrc:/imgs/menumode/recipe.png"
                    name: "recipe"
                }
                ListElement {
                    src: "qrc:/imgs/menumode/chefmode.png"
                    name: "chefmode"
                }
            }
        }






        // bake mode
        Text {
            id: tBake
            height: 35
            opacity: 0
            color: "white"
            anchors.top: line.bottom
            anchors.topMargin: 0+700//
            anchors.horizontalCenter: parent.horizontalCenter
            text: "Bake"
            font.pixelSize: 20  //to 36
            font.family: "GothamBold"
        }

        ListView
        {
            id: listV
//            property real rOpacity: 0.0
            opacity: 0.0
            visible: opacity === 0 ? false : true
            width: 200
            height: 762
            anchors.top: tBake.bottom
            anchors.topMargin: 700//
            anchors.horizontalCenter: parent.horizontalCenter
            spacing: 30
            clip: true

            delegate: Rectangle {
                id: pxx
                width: 120
                height: 120
                radius: 0
                color: "transparent"
                anchors.horizontalCenter: parent.horizontalCenter
                property string name: model.name

//                Image {
//                    visible: name !== 'e'
//                    anchors.centerIn: parent
//                    source: "qrc:/imgs/bkmode/bkbg.png"
//                    width: 130;height: 130;
////                    anchors.horizontalCenter: parent.horizontalCenter
//                }

                Image {
                    source: src //"qrc:/imgs/bkmode/bktoast.png"
                    width: 120
                    height: 120
                    anchors.centerIn: parent
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            if (pxx.name === "bktoast") {
                                seqRun([saHideBake, saShowToast], 300)
                                saLighting.start()
                                funBacks.push(backFromToast)
//                                playpause.opacity = 0.4
                            }
                        }
                    }
                }

            }

            model: ListModel {
                ListElement {
                    src: "qrc:/imgs/bkmode/bkroast.png"
                    name: "bktoast"
                }

                ListElement {
                    src: "qrc:/imgs/bkmode/bkconvection.png"
                    name: "bkconvection"
                }

                ListElement {
                    src: "qrc:/imgs/bkmode/bkdouble.png"
                    name: "bkdouble"
                }

                ListElement {
                    src: "qrc:/imgs/bkmode/bkpy.png"
                    name: "bkpy"
                }

                ListElement {
                    src: "qrc:/imgs/bkmode/bkroticonv.png"
                    name: "bkroticonv"
                }

                ListElement {
                    src: "qrc:/imgs/bkmode/bkroti.png"
                    name: "bkroti"
                }

                ListElement {name: "e"}
                ListElement {name: "e"}
                ListElement {name: "e"}

            }
        }





        // bake-toast mode
        Text {
            id: tToast
            height: 35
            opacity: 0
            color: "white"
            anchors.top: line.bottom
            anchors.topMargin: 0+700//
            anchors.horizontalCenter: parent.horizontalCenter
            text: "Toast"
            font.pixelSize: 20  //to 36
            font.family: "GothamBold"
        }

        ListView
        {
            id: listVToast
            property real rOpacity: 0.0
            opacity: 1.0
            width: 200
            height: 762
            anchors.top: tToast.bottom
            anchors.topMargin: 700//
            anchors.horizontalCenter: parent.horizontalCenter
            spacing: 30
            clip: true
            visible: opacity === 0 ? false : true

            delegate: Rectangle {
                id: pxxR
                width: 120
                height: 120
                color: "transparent"
                anchors.horizontalCenter: parent.horizontalCenter
                property string name: model.name

                Image {
                    source: src //"qrc:/imgs/bkmode/bktoast.png"
                    opacity: name === "preheat" ? listVToast.rOpacity : parent.opacity
                    width: 120
                    height: 120
                    anchors.centerIn: parent
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            if (pxxR.name === "temp") {
                                if (baketoastModel.get(0).src === "qrc:/imgs/toastmode/temp.png") {
                                    turnOffAll()
                                    turnOnTemp()
                                } else {
                                    turnOffTemp()
                                }
                            }
                            else if (pxxR.name === "addsteam") {
                                if (baketoastModel.get(2).src === "qrc:/imgs/toastmode/addsteam.png") {
                                    turnOffAll()
                                    turnOnSteam()
                                }
                                else {
                                    turnOffSteam()
                                }
                            }
                            else if (pxxR.name === "time") {
                                if (baketoastModel.get(1).src === "qrc:/imgs/toastmode/time.png") {
                                    turnOffAll()
                                    turnOnTime()
                                }
                                else {
                                    turnOffTime()
                                }
                            }
                            else if (pxxR.name === "preheat") {
                                if (baketoastModel.get(3).src === "qrc:/imgs/toastmode/preheat.png") {
                                    turnOffAll()
                                    turnOnPreheat()
                                }
                                else {
                                    turnOffPreheat()
                                }
                            }
                        }
                    }
                }
            }

            model: ListModel {
                id: baketoastModel
                ListElement {
                    src: "qrc:/imgs/toastmode/temp.png"
                    name: "temp"
                }

                ListElement {
                    src: "qrc:/imgs/toastmode/time.png"
                    name: "time"
                }

                ListElement {
                    src: "qrc:/imgs/toastmode/addsteam.png"
                    name: "addsteam"
                }

                ListElement {
                    src: "qrc:/imgs/toastmode/preheat.png"
                    name: "preheat"
                }

            }
        }

    }

    Rectangle {
        id: wt
        anchors.fill: parent
        color: "white"
        opacity: 0
        Behavior on opacity {enabled: isAniEnabled; PropertyAnimation { duration: 500}}
    }

//    Image {
//        id: bg
////        visible: false
//        source: "qrc:/imgs/bgMicroWave.png"
//        anchors.fill: parent
//        opacity: 0
//        Behavior on opacity {enabled: isAniEnabled; PropertyAnimation { duration: 500}}
//    }

    Rectangle {
        id: bg
        color: "white"
        anchors.fill: parent
        opacity: 0.5
        Behavior on opacity {enabled: isAniEnabled; PropertyAnimation { duration: 500}}
    }

    Image {
        id: iChicken_ing
        source: "qrc:/imgs/chicken.png"
        anchors.fill: parent
        opacity: 0.5
        Behavior on opacity {enabled: isAniEnabled; PropertyAnimation { duration: 500}}
    }

    Rectangle {
        id: rectVid
        anchors.fill: parent
        opacity: 0.1
        Behavior on opacity {enabled: isAniEnabled; PropertyAnimation { duration: 1000}}
        MediaPlayer {
            id: mp
            source: "file:///c:/videos/steam.mov"
            onStopped: rectVid.opacity = 0.1
        }

        VideoOutput {
            id: video
            anchors.fill: parent
            source: mp
            fillMode: VideoOutput.Stretch
            flushMode: VideoOutput.LastFrame
            z: 100
        }
    }


    ThermoMeter {
        id: tmeter
//        curTemp: "220°c"
        visible: opacity === 0 ? false : true
        anchors.right: parent.right
        anchors.rightMargin: 322
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 100
        opacity: 0
        Behavior on opacity { PropertyAnimation { duration: 300}}
    }


    Image {
        id: topLighting
        opacity: 0
        source: "qrc:/imgs/toastmode/top-lighting.png"
        anchors.top: parent.top
        anchors.horizontalCenter: parent.horizontalCenter
        Behavior on opacity { enabled: isAniEnabled; PropertyAnimation { duration: 300}}
    }

    Image {
        id: bottomLighting
        opacity: 0
        source: "qrc:/imgs/toastmode/bottom-lighting.png"
        anchors.bottom: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        Behavior on opacity { enabled: isAniEnabled; PropertyAnimation { duration: 300}}
    }


//    Text {
//        id: min30
//        anchors.top: parent.top
//        anchors.horizontalCenter: parent.horizontalCenter
//        text: "00:30"
//        color: "white"
//        font.pixelSize: 360
//        font.family: "UNDA Circle"
//        font.letterSpacing: 10
//        opacity: 0
//        Behavior on opacity { PropertyAnimation { duration: 500;}}
//    }

    Image {
        id: min30
        anchors.top: parent.top
        anchors.topMargin: 50
        anchors.horizontalCenter: parent.horizontalCenter
        property int ind: 30
        source: "qrc:/imgs/countdown/00_30.png"
        opacity: 0
        Behavior on opacity { PropertyAnimation { duration: 300;}}
    }

    Image {
        id: imgCompleted
        width: 240
        height: 240
        source: "qrc:/imgs/menumode/completed.png"
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: parent.top
        anchors.topMargin: 219
        opacity: 0
        Behavior on opacity { PropertyAnimation { duration: 500;}}
    }

    Image {
        id: tComp
        width: 880
        height: 225
        anchors.top: parent.top
        anchors.topMargin: 462
        anchors.left: parent.left
        anchors.leftMargin: 520
//        text: "Completed"
//        color: "white"
//        font.pixelSize: 240
//        font.family: "UNDA Circle"
        source: "qrc:/imgs/complete.png"
        opacity: 0
        Behavior on opacity { enabled: isAniEnabled; PropertyAnimation { duration: 500;}}
    }


    Rectangle {
        id: tempTime
        opacity: 0
        Behavior on opacity { enabled: isAniEnabled; PropertyAnimation { duration: 500;}}
        color: "transparent"
        width: 872
        height: 80
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 176
        Image {
            id: iTemp
            source: "qrc:/imgs/menumode/temp.png"
            anchors.left: parent.left
            anchors.bottom: parent.bottom
        }
        Text {
            id: tTemp
            text:tmeter.displayNum+"°c"
            color: "white"
            font.family: "GothamBold"
            font.pixelSize: 96
            anchors.left: iTemp.right
            anchors.leftMargin: 10
            anchors.bottom: parent.bottom
            anchors.bottomMargin: -10
        }
        Image {
            id: iTime
            source: "qrc:/imgs/menumode/time.png"
            anchors.left: parent.left
            anchors.leftMargin: 520
            anchors.bottom: parent.bottom
        }
        Text {
            id: tTime
            text: "30min"
            color: "white"
            font.family: "GothamBold"
            font.pixelSize: 96
            anchors.left: iTime.right
            anchors.leftMargin: 10
            anchors.bottom: parent.bottom
            anchors.bottomMargin: -10
        }
    }


    MediaPlayer {
        id: sound_taskStart
        source: "qrc:/sound/taskStart.mp3"
    }

    MediaPlayer {
        id: sound_taskFinished
        source: "qrc:/sound/taskCompleted.mp3"
    }



    function showBtnTaste() {
        isAniEnabled = false
        isAniEnabled = true

    }


    Timer {
        id: timerTest
        repeat: false
        interval: 100
        onTriggered: {
            showBtnTaste()
        }
    }



    function resetAniOther() {

        isAniEnabled = false
        bg.opacity = 0
        imgBack.opacity = 0
        iChicken_ing.opacity = 0
        tComp.opacity = 0
        imgCompleted.opacity = 0
        tempTime.opacity = 0
        rectVid.opacity = 0.1

        saLighting.stop()
        bottomLighting.opacity = 0
        topLighting.opacity = 0

        btnHome.opacity = 0
        btnHome.anchors.topMargin = 70
        back.opacity = 1
        back.anchors.topMargin = 0
        back.scale = 1
        funBacks = [backFromMenu]

//        min30.text = "00:30"
        min30.ind = 30
        min30.source = "qrc:/imgs/countdown/00_30.png"
        timerCountDown.interval = 1000

        sideMenu.opacity = 0

        isAniEnabled = true

        wt.opacity = 1
    }



    function resetAni() {

        print("menumode resetAni called")

        timerShowWhite.stop()

        isAniEnabled = false
        bg.opacity = 0
        imgBack.opacity = 0
        iChicken_ing.opacity = 0
        tComp.opacity = 0
        imgCompleted.opacity = 0
        tempTime.opacity = 0
        rectVid.opacity = 0.1

        saLighting.stop()
        bottomLighting.opacity = 0
        topLighting.opacity = 0

        btnHome.opacity = 0
        btnHome.anchors.topMargin = 70
        back.opacity = 1
        back.anchors.topMargin = 0
        back.scale = 1
        funBacks = [backFromMenu]

        min30.ind = 30
        min30.source = "qrc:/imgs/countdown/00_30.png"
        timerCountDown.interval = 1000

        wt.opacity = 0
        sideMenu.opacity = 0.7

        isAniEnabled = true
    }

    function playAni() {
        resetAni()

        bg.opacity = 0.5
        imgBack.opacity = 1.0

        // show up menu mode
        saShowMainMenu.start()
        timerTest.start()

        if (funBacks.length === 0) {
            funBacks.push(backFromMenu)
        }
    }


    SequentialAnimation {
        id: saShowMainMenu
        ParallelAnimation {
            PropertyAnimation { target: listMenu; duration: 300; property: "opacity"; from: 0; to: 1}
            PropertyAnimation { target: listMenu; duration: 300; property: "anchors.topMargin"; from: 200; to: 78}
        }
    }

    SequentialAnimation {
        id: saHideMainMenu
        ParallelAnimation {
            PropertyAnimation { target: listMenu; duration: 300; property: "opacity"; from: 1; to: 0}
            PropertyAnimation { target: listMenu; duration: 300; property: "anchors.topMargin"; from: 78; to: 0}
        }
    }


    SequentialAnimation {
        id: saShowBake
        ParallelAnimation {
            PropertyAnimation { target: tBake; duration: 300; property:"font.pixelSize"; from:20; to: 36;}
            PropertyAnimation { target: tBake; duration: 300; property:"opacity"; from:0; to: 1;}
            PropertyAnimation { target: tBake; duration: 300; property:"anchors.topMargin"; from:200; to: 50;}
        }
        ParallelAnimation {
            PropertyAnimation { target: listV; property: "opacity"; from: 0; to: 1; duration: 300; }
            PropertyAnimation { target: listV; property: "anchors.topMargin"; from:200; to:78; duration: 300; }
        }
    }

    SequentialAnimation {
        id: saHideBake
        ParallelAnimation {
            PropertyAnimation { target: tBake; duration: 300; property:"font.pixelSize"; from:36; to: 30;}
            PropertyAnimation { target: tBake; duration: 300; property:"opacity"; from:1; to: 0;}
            PropertyAnimation { target: tBake; duration: 300; property:"anchors.topMargin"; from:50; to: 0;}
        }
        ParallelAnimation {
            PropertyAnimation { target: listV; property: "opacity"; from: 1; to: 0; duration: 300; }
            PropertyAnimation { target: listV; property: "anchors.topMargin"; from:78; to:0; duration: 300; }
        }
    }


    SequentialAnimation {
        id: saShowToast
        ParallelAnimation {
            PropertyAnimation { target: tToast; duration: 300; property:"font.pixelSize"; from:30; to: 36;}
            PropertyAnimation { target: tToast; duration: 300; property:"opacity"; from:0; to: 1;}
            PropertyAnimation { target: tToast; duration: 300; property:"anchors.topMargin"; from:200; to: 50;}
        }
        ParallelAnimation {
            PropertyAnimation { target: listVToast; property: "opacity"; from: 0; to: 1; duration: 300; }
            PropertyAnimation { target: listVToast; property: "rOpacity"; from: 0; to: 1; duration: 300; }
            PropertyAnimation { target: listVToast; property: "anchors.topMargin"; from:200; to:78; duration: 300; }
        }
    }

    SequentialAnimation {
        id: saHideToast
        ParallelAnimation {
            PropertyAnimation { target: tToast; duration: 300; property:"font.pixelSize"; from:36; to: 30;}
            PropertyAnimation { target: tToast; duration: 300; property:"opacity"; from:1; to: 0;}
            PropertyAnimation { target: tToast; duration: 300; property:"anchors.topMargin"; from:50; to: 0;}
        }
        ParallelAnimation {
            PropertyAnimation { target: listVToast; property: "opacity"; from: 1; to: 0; duration: 300; }
            PropertyAnimation { target: listVToast; property: "anchors.topMargin"; from:78; to:0; duration: 300; }
        }
    }

    SequentialAnimation {
        id: saLighting
        loops: Animation.Infinite
        PropertyAnimation { targets: [topLighting, bottomLighting]; duration: 700; property: "opacity"; from: 0; to: 1}

        PauseAnimation {
            duration: 200
        }
        PropertyAnimation { targets: [topLighting, bottomLighting]; duration: 700; property: "opacity"; from: 1; to: 0}
        PauseAnimation {
            duration: 200
        }
    }

    SequentialAnimation {
        id: saShowChickening
        PropertyAnimation { target: bg; property:"opacity"; from: 0.8; to: 0.5; duration: 1000;}
        ParallelAnimation {
            PropertyAnimation { target: iChicken_ing; property:"opacity"; from: 0; to: 0.5; duration: 1000;}
            PropertyAnimation { target: rectVid; property:"opacity"; from: 0; to: 0.5; duration: 1000;}
        }
    }

    SequentialAnimation {
        id: saHideBack
        ParallelAnimation {
            PropertyAnimation { target: back; property:"opacity"; from: 1; to: 0; duration: 300;}
            PropertyAnimation { target: back; property:"anchors.topMargin"; from: 0; to: -20; duration: 300;}
            PropertyAnimation { target: back; property:"scale"; from: 1; to: 0.8; duration: 300;}
            PropertyAnimation { target: listVToast; property: "rOpacity"; from: 1; to: 0; duration: 300; }
        }
    }


    SequentialAnimation {
        id: saShowHome
        PropertyAnimation { target: listVToast; property:"opacity"; from: 1; to: 0; duration: 300;}
        PropertyAnimation { target: tToast; property:"opacity"; from: 1; to: 0; duration: 500;}
        ParallelAnimation {
            PropertyAnimation { target: btnHome; property:"opacity"; from: 0; to: 1; duration: 500;}
            PropertyAnimation { target: btnHome; property:"anchors.topMargin"; from: 70; to: 0; duration: 500;}
        }
    }


    property int nSaIndex: 0
    property var arrSas: []
    Timer {
        id: timerSa
        repeat: true
        onTriggered: {
            nSaIndex += 1
            if (nSaIndex === arrSas.length) {
                stop()
                return
            }
            arrSas[nSaIndex].start()
        }
    }

    function seqRun(sas, inter) {
        nSaIndex = 0
        arrSas = sas
        timerSa.interval = inter
        var theSa = arrSas[0]
        theSa.start()
        timerSa.start()
    }


    function turnOnTemp() {
        tmeter.opacity = 1
        baketoastModel.get(0).src = "qrc:/imgs/toastmode/temp-focus.png"
    }

    function turnOffTemp()  {
        tmeter.opacity = 0
        baketoastModel.get(0).src = "qrc:/imgs/toastmode/temp.png"
    }

    function turnOnSteam() {
        baketoastModel.get(2).src = "qrc:/imgs/toastmode/addsteam-focus.png"
    }

    function turnOffSteam() {
        baketoastModel.get(2).src = "qrc:/imgs/toastmode/addsteam.png"
    }

    function turnOnTime() {
        baketoastModel.get(1).src = "qrc:/imgs/toastmode/time-focus.png"
    }

    function turnOffTime() {
        baketoastModel.get(1).src = "qrc:/imgs/toastmode/time.png"
    }

    function turnOnPreheat() {
        baketoastModel.get(3).src = "qrc:/imgs/toastmode/preheat-focus.png"
    }

    function turnOffPreheat() {
        baketoastModel.get(3).src = "qrc:/imgs/toastmode/preheat.png"
    }

    function turnOffAll() {
        turnOffPreheat()
        turnOffSteam()
        turnOffTemp()
        turnOffTime()
    }

    function backFromMenu() {
        emit: sigHome()
    }

    function backFromBake() {
        seqRun([saHideBake, saShowMainMenu], 300)
    }

    function backFromToast() {
        seqRun([saHideToast, saShowBake], 300)
        saLighting.stop()
        topLighting.opacity = 0
        bottomLighting.opacity = 0
        turnOffTemp()
    }




    property int nFunIndex: 0
    property var arrFuns: []
    property var arrInters: []
    Timer {
        id: timerFun
        repeat: true
        onTriggered: {
            nFunIndex += 1
            if (nFunIndex === arrFuns.length) {
                stop()
                return
            }
            interval = arrInters[nFunIndex]
            arrFuns[nFunIndex]()
        }
    }

    Timer {
        id: timerCountDown
        repeat: true
        interval: 1000
        onTriggered: {
//            var t = min30.text.split(":")[1]-""
//            t -= 1
//            if (t < 0) {
//                timerCountDown.stop()
//                return
//            }
//            if (t < 10) {
//                t = "0"+t
//            }
//            min30.text = "00:"+t

            min30.ind -= 1
            if (min30.ind === 15) {
                interval = 1250
            }
            if (min30.ind < 1) {
                timerCountDown.stop()
                return
            }
            var t = min30.ind + ""
            if (min30.ind < 10)  {
                t = '0'+min30.ind
            }
            var tSrc = "qrc:/imgs/countdown/00_"+t+".png"
            min30.source = tSrc
        }
    }


    function seqRunFun(funs, inters) {
        nFunIndex = 0
        arrFuns = funs
        arrInters = inters
        timerFun.interval = arrInters[0]
        var theFun = arrFuns[0]
        theFun()
        timerFun.start()
    }


    function showChickeningFull() {
        bg.opacity = 0.5
        iChicken_ing.opacity = 1.0
        timerCountDown.start()
    }

    function showTempTime() {
        min30.opacity = 1
        tempTime.opacity = 1
    }

    function playTaskStartSound() {
        sound_taskStart.play()
        saHideBack.start()
    }

    function taskFinished() {
        sound_taskFinished.play()
        min30.opacity = 0
        imgCompleted.opacity = 1
        tComp.opacity = 1
        tempTime.opacity = 0
        saShowHome.start()
        saLighting.stop()
        topLighting.opacity = 0
        bottomLighting.opacity = 0
        timerShowWhite.start()
    }

    function playSteam() {
//        bg.opacity = 0.5
        rectVid.opacity = 0.5
        mp.play()
    }

    function startTask() {
        resetAni()
        saLighting.start()
        turnOffAll()
        playTaskStartSound()
        seqRunFun([showChickeningFull,showTempTime,playSteam,taskFinished],
                  [500,15000,19500,3000])
    }


}



